#include<iostream>
#include<list>
#include<deque>
#include<algorithm>
using namespace std;

struct Display
{
	void operator()(int i)
	{
		cout << i << " ";
	}
};

int main()
{
	list<int>alist = { 1,2,3,4,5,6,7,8 };
	deque<int>odd;
	deque<int>even;

	list<int>::iterator it = alist.begin();
	for (; it != alist.end(); it++)
	{
		if ((*it) % 2 == 0)
		{
			even.push_back(*it);
		}
		else
		{
			odd.push_back(*it);
		}
	}

	for_each(even.begin(), even.end(), Display());
	cout << endl;
	for_each(odd.begin(), odd.end(), Display());
	return 0;
}